<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: #000;
    }
  </style>
</head>
<body>
  <div class="box"></div>
  <script>
    // 1. 定时器-间歇函数
    let timer1 = setInterval(() => {
      console.log("1s执行一次");
    }, 1000);

    function fn() {
      console.log("2s执行一次");
    }
    // fn是函数名 不要加()
    let timer2 = setInterval(fn, 2000);

    console.log("timer1", timer1);
    console.log("timer2", timer2);

    // 停止定时器
    clearInterval(timer1);
    clearInterval(timer2);

    // 2. 延时函数
    let timer3 = setTimeout(() => {
      document.querySelector('.box').style.backgroundColor = 'red';
    }, 3000);
    
    
  </script>
</body>
</html>